//DHCOutPhLAddItm
var SelectedRow = 0;
function BodyLoadHandler() {
	var baddobj=document.getElementById("BInsert");
	if (baddobj) baddobj.onclick=Badd_click;
	var obj=document.getElementById("BUpdate");
	if (obj) obj.onclick=Bupdate_click;
	BReprintobj=document.getElementById("BRetrieve");
 BReprintobj.style.visibility = "hidden";


}
function getpharmacy(str) {

var ctlocobj=document.getElementById('ctloc');
var CPhLocDescobj=document.getElementById('PhLocDesc');
var tem=str.split("^");

ctlocobj.value=tem[0];
CPhLocDescobj.value=tem[1];

}

function GetFZLoc(str) {

var ctlocobj=document.getElementById('OrdLoc');
var CPhLocDescobj=document.getElementById('OrdLocDesc');
var tem=str.split("^");
//alert(tem[1]);

ctlocobj.value=tem[0];
CPhLocDescobj.value=tem[1];

}

function GetInc(str)
{
var incobj=document.getElementById('inc');
var tem=str.split("^");

incobj.value=tem[1];
DHCMZYF_setfocus("BInsert")
	
	
}

function IncDesc_lookuphandler(e) {
	if (evtName=='IncDesc') {
		window.clearTimeout(evtTimer);
		evtTimer='';
		evtName='';
	}
	var type=websys_getType(e);
	var key=websys_getKey(e);
	if ((type=='click')||((type=='keydown')&&(key==117))||((type=='keydown')&&(key==13))) {
		var url='websys.lookup.csp';
		url += '?ID=d51313iIncDesc&CONTEXT=Kweb.DHCOutPhRetrieve:QueryPhDesc&TLUDESC='+t['IncDesc'];
		url += "&TLUJSF=GetInc";
		var obj=document.getElementById('ctloc');
		if (obj) url += "&P1=" + websys_escape(obj.value);
		var obj=document.getElementById('IncDesc');
		if (obj) url += "&P2=" + websys_escape(obj.value);
		websys_lu(url,1,'');
		return websys_cancel();
	}
}
	var obj=document.getElementById('IncDesc');
	if (obj) obj.onkeydown=IncDesc_lookuphandler;

function SelectRowHandler()	{
	var eSrc=window.event.srcElement;
	var objtbl=document.getElementById('tDHCOutPhLAddItm');
	var rows=objtbl.rows.length;
	var lastrowindex=rows - 1;
	var rowObj=getRow(eSrc);
	var selectrow=rowObj.rowIndex;
	if (!selectrow) return;
	var obj=document.getElementById('OrdLocDesc');
	var obj1=document.getElementById('PhLocDesc');
	var obj3=document.getElementById('CheckStop');
	var obj5=document.getElementById('ctloc');
	var obj2=document.getElementById('IncDesc');
	var obj6=document.getElementById('OrdLoc');

	var SelRowObj=document.getElementById('TOrdLocDescz'+selectrow);
	var SelRowObj1=document.getElementById('TYFDescz'+selectrow);
	var SelRowObj2=document.getElementById('TIncDescz'+selectrow);
    var SelRowObj3=document.getElementById('TDoFlagz'+selectrow);
  var SelRowObj4=document.getElementById('TPhlai_Rowidz'+selectrow);
  
  var SelRowObj5=document.getElementById('TPhlocz'+selectrow); 
  var SelRowObj6=document.getElementById('TOrdLocz'+selectrow);    
	obj.value=SelRowObj.innerText;
	obj1.value=SelRowObj1.innerText;
	obj2.value=SelRowObj2.innerText;
	obj5.value=SelRowObj5.value;
	obj6.value=SelRowObj6.value;
	if (SelRowObj3.innerText==t['yes']){obj3.checked=true}
	  else  {obj3.checked=false}
   
	SelectedRow = selectrow;
}

function Bupdate_click()	
{
	selectrow=SelectedRow;
	
	var rowid=document.getElementById('TPhlai_Rowidz'+selectrow).value
    var use=document.getElementById('CheckStop').checked;
    var useval=""
    if (use==true){use="1";useval=t['yes']}
    else
      {use="0";useval=t['no']}
  
     var pid=document.getElementById('up');
	if (pid) {var encmeth=pid.value} else {var encmeth=''};
	if (cspRunServerMethod(encmeth,rowid,use)!='0')
	 {	alert(t['upfail']);
	return;}
		
	else {		   
	    alert(t['upok']);
	    document.getElementById('TDoFlagz'+selectrow).innerText=useval
	    
		}
	

}


function Badd_click()	
{
	//selectrow=SelectedRow;
	var ctloc=document.getElementById('ctloc').value;
	if (ctloc=="") {
		alert(t['pharmacyisnull']);
		return;}
	var ordloc=document.getElementById('OrdLoc').value;
	if (ordloc=="") {
		alert(t['ordlocisnull']);
		return;}
    var use=document.getElementById('CheckStop').checked;
    var inc=document.getElementById('inc').value;
    var ordlocdesc=document.getElementById('OrdLocDesc').value;
    var phlocdesc=document.getElementById('PhLocDesc').value;
   if (inc==''){
		alert(t['incisnull']);
		return;}

    if (use==true){use="1";}
    else
      {use="0";}
   
     var pid=document.getElementById('ins');
	if (pid) {var encmeth=pid.value} else {var encmeth=''};
	var retval=cspRunServerMethod(encmeth,ctloc,ordloc,use,inc)
	 if (retval=="-2"){alert(t['ordlochadcode']);return;}
	 else if (retval!=0){alert(t['insfail']);return;}
	 else
	 {alert(t['insok']);
	 
	 
	  var lnk = "websys.default.csp?WEBSYS.TCOMPONENT=DHCOutPhLAddItm&PhLocDesc="+phlocdesc+"&OrdLocDesc="+ordlocdesc+"&ctloc="+ctloc+"&OrdLoc="+ordloc
   location.href=lnk;
  
	 
	// window.location.reload();
	 }

}
function SetPid(value) 
{  
	if (value!="0")
	{alert(t['05']);
	return;
		}
	try {		   
	    alert(t['06']);
	    window.location.reload();
		} catch(e) {};
}
function CleartDHCOPAdm()
{
	var objtbl=document.getElementById('tDHCOPReturn');
	var rows=objtbl.rows.length;
	var lastrowindex=rows-1;
	for (var j=1;j<lastrowindex+1;j++) {
		objtbl.deleteRow(1);
	//alert(j);
	}
}

function DHCMZYF_setfocus(objName) {
	window.setTimeout('DHCMZYF_setfocus2(\''+objName+'\')',300);
}

function DHCMZYF_setfocus2(objName) {
	var obj=document.getElementById(objName);
	if (obj) {
		try {obj.focus();obj.select();	} catch(e) {}  }
    }
document.body.onload = BodyLoadHandler;
